import { ImagesConst } from "../../resource/ImagesConst";
import { FootBallGameConst } from "./FootBallGameConst";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { FGTeamInfo } from "./FGTeamInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _teamInfo } from "../../../../this/_teamInfo";
type int = number;
//class FGTeamItem
    
    export  class FGTeamItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public get group(): int
        {
            return this._group;
        }

        public set group(arg1: int)
        {
            this._group = arg1;
            return;
        }

        public get isA(): Boolean
        {
            return this.teamInfo && this.teamInfo.gameInfo.teamA == this._id;
        }

        public get type(): int
        {
            return this._type;
        }

        public set type(arg1: int)
        {
            this._type = arg1;
            return;
        }

        public get isEnable(): Boolean
        {
            return this._isEnable;
        }

        public set isEnable(arg1: Boolean)
        {
            this._isEnable = arg1;
            return;
        }

        public updateTeamInfo(arg1: int, arg2: string): void
        {
            this._id = arg1;
            this._name = arg2;
            this.isResult = this._isResult;
            return;
        }

        public set isResult(arg1: Boolean)
        {
            this._isResult = arg1;
            if (this._isLoaded) 
            {
                this.showTeamIcon();
            }
            return;
        }

        public set isSelected(arg1: Boolean)
        {
            this._isSelected = arg1;
            return;
        }

        /* internal  */updateBg(): void
        {
            if (this._isLoaded) 
            {
                if (this._teamInfo && this._teamInfo.isHasGuess && this._teamInfo.gameInfo.guess == this._id) 
                {
                    this._bgButton.styleName = "ButtonGreenStyle";
                }
                else 
                {
                    this._bgButton.styleName = "ButtonBlueStyle";
                }
            }
            return;
        }

        /* internal  */getBgImageName(): string
        {
            var loc1=ImagesConst.TypeBg_8;
            if (this.teamInfo && this.teamInfo.gameInfo) 
            {
                var loc2=this.teamInfo.gameInfo.type;
                switch (loc2) 
                {
                    case FootBallGameConst.GROUP_TYPE_8:
                    {
                        loc1 = ImagesConst.TypeBg_8;
                        break;
                    }
                    case FootBallGameConst.GROUP_TYPE_4:
                    {
                        loc1 = ImagesConst.TypeBg_4;
                        break;
                    }
                    case FootBallGameConst.GROUP_TYPE_2:
                    {
                        loc1 = ImagesConst.TypeBg_2;
                        break;
                    }
                    case FootBallGameConst.GROUP_TYPE_1:
                    {
                        loc1 = ImagesConst.TypeBg_1;
                        break;
                    }
                }
            }
            return loc1;
        }

        /* internal  */init(): void
        {
            this._bgButton = ObjCreate.createGButton("", -25, 0, 91, 19, this, "ButtonBlueStyle");
            this._bgButton.mouseEnabled = false;
            this._box = new Object /* flash.display.Bitmap */();
            this._box.x = 0;
            this._box.y = 5;
            this.addChild(this._box);
            this._countryBitmap = new Object /* flash.display.Bitmap */();
            this._countryBitmap.x = 5;
            this._countryBitmap.y = 10;
            this.addChild(this._countryBitmap);
            this._quesBitmap = new Object /* flash.display.Bitmap */();
            this._quesBitmap.x = 12;
            this._quesBitmap.y = 0;
            this.addChild(this._quesBitmap);
            this._nameTxt = ObjCreate.createTextField("", -25, -1.5, 100, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15859633, true));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nameTxt.multiline = true;
            this._nameTxt.mouseEnabled = false;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            LoaderHelp.addResCallBack(ResFileConst.footballGuess, this.onResLoadHandler);
            return;
        }

        /* internal  */onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            var loc2=null;
            if (!this._isSelected && this._id > 0 && this.teamInfo && !this.teamInfo.isHasResult) 
            {
                loc1 = Cache.instance.footballGuess.isCanGuess(this.teamInfo.gameInfo);
                if (loc1) 
                {
                    if (!this.teamInfo.isHasGuess) 
                    {
                        loc2 = {"teamInfo": _teamInfo, "isA": this.isA};
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FootballGuessAlertWindowOpen, loc2));
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(51142));
                }
            }
            return;
        }

        /* internal  */onResLoadHandler(): void
        {
            this._isLoaded = true;
            this.updateBg();
            this.showTeamIcon();
            return;
        }

        /* internal  */showTeamIcon(): void
        {
            if (this._id != 0) 
            {
                this._quesBitmap.bitmapData = null;
            }
            else 
            {
                this._quesBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.FGQuestion);
                this._quesBitmap.height = 19;
            }
            return;
        }

        public get teamInfo(): FGTeamInfo
        {
            return this._teamInfo;
        }

        public set teamInfo(arg1: FGTeamInfo)
        {
            var loc1=null;
            this._teamInfo = arg1;
            if (this._name) 
            {
                loc1 = FootBallGameConst.getNameColor(arg1.gameInfo.type);
                this._nameTxt.htmlText = HTMLUtil.addColor(this._name, loc1);
            }
            this.updateBg();
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bgButton: GButton;

        /* internal */ /* var */_box: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_countryBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_quesBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_mask: Object /* flash.display.Sprite */;

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_group: int;

        /* internal */ /* var */_isLoaded: Boolean;

        /* internal */ /* var */_id: int;

        /* internal */ /* var */_name: string;

        /* internal */ /* var */_isSelected: Boolean;

        /* internal */ /* var */_isEnable: Boolean;

        /* internal */ /* var */_teamInfo: FGTeamInfo;

        /* internal */ /* var */_isResult: Boolean;
    }
